﻿using Kingdee.BOS.Cache;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RK.FormPlugin.XHX
{
    [Description("通用单据插件-按钮(tb_ClearAllCache)清空所有缓存")]
    public class DzOnLoad : AbstractDynamicFormPlugIn
    {
        /// <summary>
        /// 加载，如果是树形维护，清空所有缓存
        /// </summary>
        /// <param name="e"></param>
        public override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (this.View.BillBusinessInfo != null
                && this.View.BillBusinessInfo.GetForm() != null
                && this.View.BillBusinessInfo.GetForm().Id == "ENG_BOMTREE")
            {
                KCacheManagerFactory.Instance.ClearAllCache();
            }
        }
        /// <summary>
        /// 物料清单正查，树形子项点击增加清空缓存
        /// </summary>
        /// <param name="e"></param>
        public override void CustomEvents(CustomEventsArgs e)
        {
            base.CustomEvents(e);
            if (e.Key == "MFG_MaterialTree" && e.EventName == "TreeNodeClick")
            {
                string eventArgs = e.EventArgs;
                if (eventArgs.Contains("m"))
                {
                    KCacheManagerFactory.Instance.ClearAllCache();
                }
            }
        }
    }
}
